﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DatabaseCompare.Model
{


    /// <summary>
    /// 列 比较结果
    /// </summary>
    public class ColumnCompareResult : CompareAbleResult<ColumnInfo>
    {

        /// <summary>
        /// 列的顺序不同.
        /// </summary>
        public bool ColumnIdDifference { set; get; }


        /// <summary>
        /// 数据类型不同
        /// </summary>
        public bool DataTypeDifference { set; get; }


        /// <summary>
        /// 占用字节数不同.
        /// </summary>
        public bool MaxLengthDifference { set; get; }

        /// <summary>
        /// 长度不同
        /// </summary>
        public bool PrecisionDifference { set; get; }

        /// <summary>
        /// 小数位数不同
        /// </summary>
        public bool ScaleDifference { set; get; }


        /// <summary>
        /// 是否允许非空不同.
        /// </summary>
        public bool IsNullAbleDifference { set; get; }


        /// <summary>
        /// 是否是自增ID不同
        /// </summary>
        public bool IsIDEntityDifference { set; get; }


        /// <summary>
        /// 是否是主键不同
        /// </summary>
        public bool IsPrimaryKeyDifference { set; get; }


        public override string GetDifferenceString()
        {

            StringBuilder buff = new StringBuilder();
            buff.Append("不匹配[");

            if (ColumnIdDifference)
            {
                buff.AppendFormat("列顺序({0},{1})", Left.ColumnId, Right.ColumnId);
            }
            if (DataTypeDifference)
            {
                buff.AppendFormat("数据类型({0},{1})", Left.DataType, Right.DataType);
            }
            if (MaxLengthDifference)
            {
                buff.AppendFormat("占用字节数({0},{1})", Left.MaxLength, Right.MaxLength);
            }
            if (PrecisionDifference)
            {
                buff.AppendFormat("长度({0},{1})", Left.Precision, Right.Precision);
            }
            if (ScaleDifference)
            {
                buff.AppendFormat("长度({0},{1})", Left.Scale, Right.Scale);
            }
            if (IsNullAbleDifference)
            {
                buff.AppendFormat("是否允许非空({0},{1})", Left.IsNullAble, Right.IsNullAble);
            }
            if (IsPrimaryKeyDifference)
            {
                buff.AppendFormat("是否是主键({0},{1})", Left.IsPrimaryKey, Right.IsPrimaryKey);
            }
            if (CommentDifference)
            {
                buff.AppendFormat("备注/说明信息({0},{1})", Left.Comment, Right.Comment);
            }
            buff.Append("]");
            return buff.ToString();

        }
    }

}
